Skip to content

Cache purge stub#6465

Open
tewaro wants to merge 3 commits intomainfrom
atewari/purge-jsrpc
Open

Cache purge stub#6465
tewaro wants to merge 3 commits intomainfrom
atewari/purge-jsrpc

Conversation

@tewaro
Copy link
Copy Markdown
Contributor

@tewaro tewaro commented Mar 31, 2026

No description provided.

@tewaro tewaro requested review from a team as code owners March 31, 2026 15:51
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm Bonk, and I've done a quick review of your PR.

This PR adds a ctx.cache stub property to ExecutionContext, delegating to a virtual Worker::Api::getCtxCacheProperty() hook that returns undefined by default.

Issues (highest severity first):

  1. [HIGH] New ctx.cache property is unconditionally exposed with no compat flag or autogate. Adding a new property to every ExecutionContext instance is a behavioral change — it could shadow user-defined cache properties or break code that checks 'cache' in ctx. Other ctx properties (exports, version, abort) are all gated behind compat flags. This needs at minimum a compat flag or autogate for staged rollout.
  2. [MEDIUM] No tests. There are no tests covering the new getCache() path or the getCtxCacheProperty() hook.
  3. [LOW] Missing TypeScript type definition. The JSG_TS_OVERRIDE blocks in JSG_RESOURCE_TYPE don't include cache, so generated TypeScript types won't reflect this property.
  4. [LOW] Comment inaccuracies. Minor comment issues flagged inline.

These comments were generated by an AI code review assistant and may not be perfect. Please use your judgment when evaluating them.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 31, 2026

Review posted successfully on PR #6465. Here's a summary of the findings:

  1. [HIGH] No compat flag or autogate: The ctx.cache property is unconditionally exposed to all workers. Other ctx properties (exports, version, abort) are all gated behind compat flags. This is a backward-compat risk since it adds a new enumerable property to every ExecutionContext.

  2. [MEDIUM] No tests: No tests cover the new code paths.

  3. [LOW] Missing TypeScript types: The JSG_TS_OVERRIDE blocks don't include cache.

  4. [LOW] Comment inaccuracies: "CacheW-enabled" typo and incorrect reference to IoChannelFactory (should be Worker::Api).

github run

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.27%. Comparing base (2ed69c4) to head (5535f5e).
⚠️ Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/api/global-scope.c++ 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6465      +/-   ##
==========================================
+ Coverage   70.95%   71.27%   +0.31%     
==========================================
  Files         428      434       +6     
  Lines      119850   121333    +1483     
  Branches    18988    19009      +21     
==========================================
+ Hits        85037    86475    +1438     
- Misses      23529    23564      +35     
- Partials    11284    11294      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tewaro tewaro requested a review from a team as a code owner March 31, 2026 16:44
@tewaro tewaro requested a review from vicb March 31, 2026 16:44
@tewaro tewaro force-pushed the atewari/purge-jsrpc branch from 8413fb6 to 5535f5e Compare April 1, 2026 18:12
@danlapid
Copy link
Copy Markdown
Collaborator

danlapid commented Apr 3, 2026

@jasnell can you review this PR please, you probably know better than I do the intricacies that are worth watching out for here.

}

jsg::JsValue ExecutionContext::getCache(jsg::Lock& js) {
// Hook for the embedding application (e.g. edgeworker) to provide a ctx.cache object.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the name edgeworker externally as Akamai has a copyright on the name (that they acquired long after we started using it but... is what it is)

Suggested change
// Hook for the embedding application (e.g. edgeworker) to provide a ctx.cache object.
// Hook for the embedding application to provide a ctx.cache object.

}

// Returns an optional cache object for Cache-enabled workers.
// The default implementation returns undefined. Overridden via IoChannelFactory.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default impl in global-scope doesn't just return undefined. It checks to see if there's an active IoContext.

return props.getHandle(js);
}

// Returns an optional cache object for Cache-enabled workers.
Copy link
Copy Markdown
Collaborator

@jasnell jasnell Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more detail about the expected return value and where the shape of that object is defined would be helpful. It's a bit unusual for a property to return a generic jsg::JsValue when the return value is expected to be an object. Is it a jsg::Object? Is is a JSG_STRUCT that happens to have a function property? Is it a jsrpc target? etc.

Copy link
Copy Markdown
Collaborator

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few nits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants